<template>
	<view class="container">
		<!-- 售后状态 -->
		<view class="status-section">
			<view class="status-info">
				<text class="status-text">{{afterSalesInfo.statusText}}</text>
				<text class="status-desc">{{afterSalesInfo.statusDesc}}</text>
			</view>
			<view class="progress-bar">
				<view 
					class="progress-item" 
					v-for="(item, index) in progressList" 
					:key="index"
					:class="{ active: item.active, completed: item.completed }"
				>
					<view class="progress-dot"></view>
					<view class="progress-line" v-if="index < progressList.length - 1"></view>
					<text class="progress-text">{{item.text}}</text>
				</view>
			</view>
		</view>
		
		<!-- 商品信息 -->
		<view class="product-section">
			<view class="section-title">商品信息</view>
			<view class="product-info">
				<image :src="afterSalesInfo.product.image" mode="aspectFill" class="product-img"></image>
				<view class="product-detail">
					<text class="product-name">{{afterSalesInfo.product.name}}</text>
					<text class="product-spec">{{afterSalesInfo.product.spec}}</text>
					<text class="product-price">¥{{afterSalesInfo.product.price}}</text>
				</view>
			</view>
		</view>
		
		<!-- 售后信息 -->
		<view class="info-section">
			<view class="section-title">售后信息</view>
			<view class="info-list">
				<view class="info-item">
					<text class="label">售后类型</text>
					<text class="value">{{afterSalesInfo.type}}</text>
				</view>
				<view class="info-item">
					<text class="label">申请时间</text>
					<text class="value">{{afterSalesInfo.applyTime}}</text>
				</view>
				<view class="info-item">
					<text class="label">问题描述</text>
					<text class="value">{{afterSalesInfo.description}}</text>
				</view>
			</view>
		</view>
		
		<!-- 处理记录 -->
		<view class="record-section">
			<view class="section-title">处理记录</view>
			<view class="record-list">
				<view 
					class="record-item" 
					v-for="(item, index) in afterSalesInfo.records" 
					:key="index"
				>
					<view class="record-time">{{item.time}}</view>
					<view class="record-content">
						<text class="record-text">{{item.content}}</text>
						<view class="record-images" v-if="item.images && item.images.length">
							<image 
								v-for="(img, imgIndex) in item.images" 
								:key="imgIndex"
								:src="img"
								mode="aspectFill"
								class="record-img"
								@click="previewImage(item.images, imgIndex)"
							></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 底部按钮 -->
		<view class="footer" v-if="afterSalesInfo.status === 'processing'">
			<button class="action-btn" @click="cancelAfterSales">取消申请</button>
			<button class="action-btn primary" @click="contactService">联系客服</button>
		</view>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 售后详情数据
const afterSalesInfo = ref({
	id: 1,
	status: 'processing',
	statusText: '处理中',
	statusDesc: '商家正在处理您的售后申请',
	product: {
		name: '重庆老火锅底料',
		spec: '500g/袋',
		price: '39.9',
		image: 'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg'
	},
	type: '退货退款',
	applyTime: '2024-03-20 14:30',
	description: '商品包装破损，影响使用',
	records: [
		{
			time: '2024-03-20 14:30',
			content: '提交售后申请',
			images: [
				'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg',
				'https://img.alicdn.com/imgextra/i2/O1CN01F0MA5j1zXb0XcYV1F_!!6000000006733-0-tps-1316-736.jpg'
			]
		},
		{
			time: '2024-03-20 15:00',
			content: '商家已收到申请，正在处理中'
		}
	]
})

// 进度列表
const progressList = ref([
	{ text: '提交申请', active: true, completed: true },
	{ text: '商家处理', active: true, completed: false },
	{ text: '退款/换货', active: false, completed: false },
	{ text: '完成', active: false, completed: false }
])

// 预览图片
const previewImage = (images, current) => {
	uni.previewImage({
		urls: images,
		current: images[current]
	})
}

// 取消售后申请
const cancelAfterSales = () => {
	uni.showModal({
		title: '提示',
		content: '确定要取消该售后申请吗？',
		success: (res) => {
			if (res.confirm) {
				uni.showLoading({
					title: '取消中...'
				})
				
				// 这里可以添加取消售后申请的接口调用
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						title: '取消成功',
						icon: 'success'
					})
					
					// 返回列表页
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
				}, 1000)
			}
		}
	})
}

// 联系客服
const contactService = () => {
	uni.makePhoneCall({
		phoneNumber: '400-123-4567'
	})
}

// 生命周期钩子
onMounted(() => {
	// 这里可以添加获取售后详情的接口调用
})
</script>

<style>
.container {
	min-height: 100vh;
	background-color: #F5F5F5;
	padding-bottom: 120rpx;
}

/* 状态区域样式 */
.status-section {
	background-color: #FFFFFF;
	padding: 40rpx 30rpx;
	margin-bottom: 20rpx;
}

.status-info {
	margin-bottom: 40rpx;
}

.status-text {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 10rpx;
	display: block;
}

.status-desc {
	font-size: 26rpx;
	color: #666;
}

.progress-bar {
	display: flex;
	justify-content: space-between;
	position: relative;
}

.progress-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	position: relative;
	flex: 1;
}

.progress-dot {
	width: 20rpx;
	height: 20rpx;
	border-radius: 50%;
	background-color: #DDDDDD;
	margin-bottom: 10rpx;
}

.progress-line {
	position: absolute;
	top: 10rpx;
	left: 50%;
	width: 100%;
	height: 2rpx;
	background-color: #DDDDDD;
	z-index: 1;
}

.progress-item:last-child .progress-line {
	display: none;
}

.progress-item.active .progress-dot {
	background-color: #D02B29;
}

.progress-item.completed .progress-dot {
	background-color: #07C160;
}

.progress-item.completed .progress-line {
	background-color: #07C160;
}

.progress-text {
	font-size: 24rpx;
	color: #666;
}

.progress-item.active .progress-text {
	color: #D02B29;
}

.progress-item.completed .progress-text {
	color: #07C160;
}

/* 商品信息样式 */
.product-section {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 20rpx;
}

.product-info {
	display: flex;
}

.product-img {
	width: 160rpx;
	height: 160rpx;
	border-radius: 10rpx;
	margin-right: 20rpx;
}

.product-detail {
	flex: 1;
}

.product-name {
	font-size: 28rpx;
	color: #333;
	margin-bottom: 10rpx;
	display: block;
}

.product-spec {
	font-size: 24rpx;
	color: #999;
	margin-bottom: 10rpx;
	display: block;
}

.product-price {
	font-size: 32rpx;
	color: #D02B29;
	font-weight: bold;
}

/* 售后信息样式 */
.info-section {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.info-list {
	display: flex;
	flex-direction: column;
}

.info-item {
	display: flex;
	margin-bottom: 20rpx;
}

.info-item:last-child {
	margin-bottom: 0;
}

.label {
	font-size: 26rpx;
	color: #666;
	width: 160rpx;
}

.value {
	font-size: 26rpx;
	color: #333;
	flex: 1;
}

/* 处理记录样式 */
.record-section {
	background-color: #FFFFFF;
	padding: 30rpx;
}

.record-list {
	display: flex;
	flex-direction: column;
}

.record-item {
	margin-bottom: 30rpx;
}

.record-item:last-child {
	margin-bottom: 0;
}

.record-time {
	font-size: 24rpx;
	color: #999;
	margin-bottom: 10rpx;
}

.record-content {
	background-color: #F5F5F5;
	padding: 20rpx;
	border-radius: 10rpx;
}

.record-text {
	font-size: 26rpx;
	color: #333;
	line-height: 1.5;
	margin-bottom: 10rpx;
	display: block;
}

.record-images {
	display: flex;
	flex-wrap: wrap;
	margin: 0 -5rpx;
}

.record-img {
	width: 160rpx;
	height: 160rpx;
	margin: 5rpx;
	border-radius: 10rpx;
}

/* 底部按钮样式 */
.footer {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	height: 100rpx;
	background-color: #FFFFFF;
	display: flex;
	align-items: center;
	padding: 0 30rpx;
}

.action-btn {
	flex: 1;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	border-radius: 40rpx;
	font-size: 28rpx;
	margin: 0 10rpx;
}

.action-btn:first-child {
	background-color: #F5F5F5;
	color: #666;
}

.action-btn.primary {
	background-color: #D02B29;
	color: #FFFFFF;
}
</style> 